/**
 * 2012-2-26
 * @author 李亚松
 * @email  lysong01@gmail.com
 * CountingGenerator.java		simple generator implementations
 * 将最基本的生成器类直接嵌套在数据生成器类中
 */
package liyasong.util;

public class CountingGenerator {
	public static class 
	Boolean implements Generator<java.lang.Boolean> {
		private boolean value = false;
		public java.lang.Boolean next() {
			value = !value;		//just flips back and forth
			return value;
		}
	}
	
	public static class 
	Byte implements Generator<java.lang.Byte> {
		private byte value = 0;			//字节类型怎么这么用？
		public java.lang.Byte next() {
			return value++;
		}
	}
	
	static char[] chars = ("abcdefghijklmnopqrstuvwxyz" + 
			"ABCDEFGHIJKLMNOPQRSTUVWXYZ").toCharArray();
	public static class
	Character implements Generator<java.lang.Character> {
		int index = -1;

		@Override
		public java.lang.Character next() {
			index = (index + 1)%chars.length;
			return chars[index];
		}
	}
	
	public static class
	String implements Generator<java.lang.String> {
		private int length = 7;
		Generator<java.lang.Character> cg = new Character();
		public String() {}
		public String(int length) {this.length = length;}
		/* (non-Javadoc)
		 * @see liyasong.util.Generator#next()
		 * 自动生成非单词字符串的绝妙方法；
		 */
		@Override
		public java.lang.String next() {
			char[] buf = new char[length];
			for (int i = 0; i < length; i++) {
				buf[i] = cg.next();
			}
			return new java.lang.String(buf);
		}
	}
	
	public static class 
	Short implements Generator<java.lang.Short> {
		private short value = 0;
		public java.lang.Short next() { return value++; }
	}
	
	public static class 
	Integer implements Generator<java.lang.Integer> {
		private int value = 0;
		public java.lang.Integer next() { return value++; }
	}
	
	public static class 
	Double implements Generator<java.lang.Double> {
		private double value = 0;
		public java.lang.Double next() { return value++; }
	}
}
